package paintball;

import game.GameMap;
import game.Player;
import java.net.Socket;

public class PaintballPlayer extends Player {
	public boolean move;
	public PaintballBullet bullet;
	int hits = 3;
	
	public PaintballPlayer(int x, int y, String playerName, Socket s) {
		super(x, y, playerName, s);
		this.setWidth(32);
		this.setHeight(32);
		this.setRespawnTime(300);
	}
	
	@Override
	public String curImgPath(){
		switch(this.state){
			case NORMAL:
				return "res/paintballplayer.gif";
			case DEAD:
				return "res/pldead.png";
		}
		return "";
	}

	@Override
	public void move(GameMap gameMap){
		if(move){
			super.move(gameMap);
			if(!canMoveWithoutGoingOutOfMap(gameMap.getWidth(), gameMap.getHeight())){
				move = false;
			}
		}
	}
	
	/**
	 * @return The fired paintball bullet
	 */
	public boolean shoot(){
		if(this.bullet == null || !this.bullet.isActive()){
			PaintballBullet pb = new PaintballBullet(this.getX(), this.getY(), this.getRotation(), this);
			this.bullet = pb;
			return true;
		}
		return false;
	}
	
	/**
	 * @param damage - the amount of damage the hit does
	 */
	public void TakeHit(int damage){
		this.hits -= damage;
		if(hits < 1){
			this.setActive(false);
			this.state = State.DEAD;
		}
	}
	
	@Override
	public void PostRespawn(){
		this.hits = 3;
	}
}
